package com.flyxiaozhu.erp.service.configurations;

import com.flyxiaozhu.erp.core.interceptors.SignatureInterceptor;
import com.flyxiaozhu.erp.service.resolvers.ContextAppResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 注册拦截器，对请求拦截，进行签名验证
 *
 * @author flyxiaozhu
 * @date 2019-04-06 14:46
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {
    @Autowired
    SignatureInterceptor signatureInterceptor; // 实例化拦截器

    @Bean
    public ContextAppResolver contextAppResolver() {
        return new ContextAppResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(signatureInterceptor);
    }

    /**
     * 自定义的参数解析对象
     *
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(contextAppResolver());
    }
}
